package cn.zxh.csdn_maven.work.flow.download.chains;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.apache.http.client.HttpClient;
import org.json.JSONObject;

import cn.zxh.csdn_maven.base.util.GetHtmlFromUrl;
import cn.zxh.csdn_maven.work.flow.download.AbstractFlowController;

public class SecondUrlFlow extends AbstractFlowController{

	@Override
	public Map<String, Object> execute(HttpClient client,
			Map<String, Object> params) throws Exception {
		Map<String, Object> result = new HashMap<String, Object>();
		String download_url = params.get("download_url").toString()+"?callback=jQuery_"+new Date().getTime() +"&_="+new Date().getTime()+"";
		Map<String, Object> headsMap=new HashMap<String, Object>();
		headsMap.put("base_url", download_url);
		headsMap.put("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0");
		headsMap.put("Host", "download.csdn.net");
		headsMap.put("Referer", "download.csdn.net");
		String html = GetHtmlFromUrl.getInstance().getHtml(headsMap);
		/**封装成json格式的string*/
		html=html.substring(1,html.length()-1);
		JSONObject jsonObject = new JSONObject(html);
		result.put("data",jsonObject);
		result.put("msg", "success");
		return result;
	}

	@Override
	public String getBaseUrl() {
		// TODO Auto-generated method stub
		return "";
	}

}
